<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            background: #ccc;
        }
        #box{
            width: 100%;
            display: flex;
            justify-content: space-evenly;
            flex-wrap: wrap;
        }
        .boxs{
            width: 460px;
            height: 270px;
            background: #fff;
            border-radius: 10px;
            list-style: none;
            margin-top: 20px;
        }
        .boxs img{
            width: 250px;
            height: 270px;   
            margin-left: 10px;  
            float: left;   
        }
        .boxs p{
            font-size: 18px;
            margin-top: 28px;
        }
    </style>
</head>
<body>
    <ul id="box">
        <!-- <li class="boxs">
            <img src="./images/iphone.jpg" alt="">
            <p>iPhone 11</p>
            <p>128GB 黑色</p>
            <p>￥5499</p>
            <p>立即购买</p>
        </li> -->
    </ul>
</body>
<script>
    var goodlist = [
        { id: 1,url:'./images/iphone.jpg',name:'iPhone 11',color:'128GB 黑色',price:'￥5499',purchase:'立即购买'},
        { id: 2,url:'./images/iphone1.jpg',name:'iPhone 8 Plus',color:'128GB 灰色',price:'￥3699',purchase:'立即购买'},
        { id: 3,url:'./images/iphone2.jpg',name:'iPhone XS Max',color:'64GB 银色',price:'￥5299',purchase:'立即购买'},
        { id: 4,url:'./images/erji.jpg',name:'AirPods',color:'配有线充电盒',price:'￥999',purchase:'立即购买'}
    ]
    goodlist.forEach(function(item,index){
        box.innerHTML +=`
        <li idx='${item.id}' class="boxs">
            <img src="${item.url}" alt="">
            <p>${item.name}</p>
            <p>${item.color}</p>
            <p>${item.price}</p>
            <p>${item.purchase}</p>
        </li>
        `
    })
    var list = document.getElementsByTagName('li');
    for(var i=0;i<list.length;i++){
        list[i].onclick = function(){
            open('商品详情页.html?id=' + this.getAttribute('idx'));
        }
    }
</script>
</html>